summaryrefslogtreecommitdiff
path: root/src/pages/blog/read/[...slug].astro
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages/blog/read/[...slug].astro')
-rw-r--r--src/pages/blog/read/[...slug].astro74
1 files changed, 41 insertions, 33 deletions
diff --git a/src/pages/blog/read/[...slug].astro b/src/pages/blog/read/[...slug].astro
index 05d68e8..348a976 100644
--- a/src/pages/blog/read/[...slug].astro
+++ b/src/pages/blog/read/[...slug].astro
@@ -9,9 +9,9 @@ import Keywords from "@components/Keywords.astro";
import Citations from "@components/Citations.astro";
import Signature from "@components/signature/Signature.astro";
import CopyrightNotice from "@components/CopyrightNotice.astro";
-import { getEntries } from "astro:content";
import { verifier as verifierPrototype } from "@lib/pgp/verify";
-import { defined, get } from "@utils/anonymous";
+import { getSigners } from "@lib/collection/helpers";
+import { get } from "@utils/anonymous";
import Authors from "@components/signature/Authors.astro";
import { getEntry } from "astro:content";
@@ -27,8 +27,9 @@ type Props = CollectionEntry<"blog">;
const post = Astro.props;
-if (defined(post.data.translationOf)) {
- const original = await getEntry(
+let original: CollectionEntry<"blog">;
+if (post.data.kind === "translation") {
+ original = await getEntry(
post.data.translationOf as CollectionEntry<"blog">,
);
@@ -40,15 +41,15 @@ if (defined(post.data.translationOf)) {
(s) => s.role === "author",
).map((s) => s.entity.id)?.[0];
const originalCoAuthors = new Set(
- (original.data.signer ?? []).filter(
+ (original.data.signers ?? []).filter(
(s) => s.role === "co-author",
).map((s) => s.entity.id),
);
- const translationAuthor = (post.data.signer ?? []).filter(
+ const translationAuthor = (post.data.signers ?? []).filter(
(s) => s.role === "author",
).map((s) => s.entity.id)?.[0];
const translationCoAuthors = new Set(
- (post.data.signer ?? []).filter(
+ (post.data.signers ?? []).filter(
(s) => s.role === "co-author",
).map((s) => s.entity.id),
);
@@ -63,7 +64,7 @@ if (defined(post.data.translationOf)) {
);
}
- const translators = (post.data.signer ?? []).filter(
+ const translators = (post.data.signers ?? []).filter(
(s) => s.role === "translator",
).map((s) => s.entity.id);
@@ -77,7 +78,8 @@ if (defined(post.data.translationOf)) {
}
}
} else {
- if (post.data.signer?.some((x) => x.role === "translator")) {
+ original = post;
+ if (post.data.signers?.some((x) => x.role === "translator")) {
throw new Error(
`Post ${post.id} is not a translation but has translators defined`,
);
@@ -89,8 +91,8 @@ const translationsSet = new Set(
(await getCollection(
"blog",
(x) =>
- x.data.translationOf?.id ===
- (post.data.translationOf !== undefined
+ (x.data.kind === "translation") && x.data.translationOf.id ===
+ (post.data.kind === "translation"
? post.data.translationOf.id
: post.id),
) ?? []).map(({ id }) => id),
@@ -102,16 +104,7 @@ const translations = [...translationsSet.values()].map((id) => ({
id,
}));
-const signers = await getEntries(
- post.data.signer?.map(get("entity")) ?? [],
-).then((x) => x.filter(defined))
- .then((x) =>
- x.map((x) => ({
- entity: x,
- role: post.data.signer?.find((y) => y.entity.id === x.id)?.role,
- }))
- )
- .then((x) => x.filter((x) => x.role !== undefined));
+const signers = await getSigners(post);
const verifier = await verifierPrototype.then((x) => x.clone());
@@ -137,7 +130,12 @@ const commit = await verification?.commit;
<html lang="pt-PT">
<head>
- <BaseHead title={post.data.title} description={post.data.description} />
+ <BaseHead
+ title={post.data.title}
+ description={"description" in post.data
+ ? post.data.description
+ : post.data.title}
+ />
</head>
<body>
@@ -151,7 +149,7 @@ const commit = await verification?.commit;
<hgroup>
<h1 itemprop="headline">{post.data.title}</h1>
{
- post.data.subtitle && (
+ "subtitle" in post.data && (
<p itemprop="alternativeHeadline" class="subtitle">
{post.data.subtitle}
</p>
@@ -159,7 +157,8 @@ const commit = await verification?.commit;
}
</hgroup>
{
- post.data.description && (
+ "description" in post.data && post.data.description &&
+ (
<section itemprop="abstract">
<h2>Resumo</h2>
{
@@ -181,7 +180,7 @@ const commit = await verification?.commit;
<Authors
verifications={verification.verifications}
expectedSigners={signers}
- commitSignerKey={commit?.signature?.keyFingerPrint}
+ commitSignerKey={commit?.signature?.signer}
/>
)
}
@@ -201,7 +200,7 @@ const commit = await verification?.commit;
post.data.dateUpdated && (
<dt>Última atualização</dt><dd>
<time
- itemprop="dateUpdated"
+ itemprop="dateModified"
datetime={toIso8601Full(post.data.dateUpdated)}
>{
new Intl.DateTimeFormat([lang], {}).format(
@@ -212,7 +211,8 @@ const commit = await verification?.commit;
)
}
{
- post.data.locationCreated && (
+ "locationCreated" in post.data &&
+ post.data.locationCreated && (
<dt
itemprop="locationCreated"
itemscope
@@ -230,15 +230,23 @@ const commit = await verification?.commit;
<hr />
<div itemprop="articleBody text"><Content /></div>
<hr />
- <Keywords keywords={post.data.keywords} />
- <Citations citations={post.data.relatedPosts} />
+ {
+ "keywords" in original.data && (
+ <Keywords keywords={original.data.keywords} />
+ )
+ }
+ {
+ "relatedPosts" in original.data && (
+ <Citations citations={original.data.relatedPosts} />
+ )
+ }
<CopyrightNotice
- author={signers[0]?.entity.data.website?.[0] ?? "Anonymous"}
- website={signers[0]?.entity.data.website?.[0]}
- email={signers[0]?.entity.data.website?.[0]}
+ author={signers[0]?.entity.data.websites?.[0] ?? "Anonymous"}
+ website={signers[0]?.entity.data.websites?.[0]}
+ email={signers[0]?.entity.data.websites?.[0]}
title={post.data.title}
dateCreated={post.data.dateCreated}
- license={post.data.license as License}
+ license={post.data.license}
/>
</article>
</main>